<?php
/**
 * @author AtomskJD
 * @copyright 2012
 */
//TODO: Удалить лишние инклуды
include_once('RAWhtml-parser-config.inc.php');
include_once(FUNCTIONS);
$self = $_SERVER['PHP_SELF'];

if (isset($_GET['curid']) ){
	setcookie('curid', $_GET['curid']);
}
if (isset($_GET['year']) ){
	setcookie('year', $_GET['year']);
}

$db = mysql_connect(HOST, LOGIN, PASSWORD) 
or die (file_put_contents(ERRLOG, mysql_error()."\r\n", FILE_APPEND) );
mysql_select_db(DBNAME, $db) 
or die (file_put_contents(ERRLOG, mysql_error()."\r\n", FILE_APPEND) );

$option = cidmenu($db);

$sql = "SELECT DISTINCT FROM_UNIXTIME(date, '%Y') as year FROM currency_rate";
$result = mysql_query($sql, $db)
or die (file_put_contents(ERRLOG, mysql_error()."\r\n", FILE_APPEND) );
while ($row = mysql_fetch_array($result, MYSQL_ASSOC) ){
    $query[] = $row;
}    
if (empty($query[0]) ) exit;

//	формируем выпадающий список лет
$year = array();
$ymenu = '<select name="year">';
$ymenu .= '<option>all</option>';
foreach ($query as $var){
	$year = $var['year'];
	$ymenu .= '<option>';
	$ymenu .= $year;
	$ymenu .= '</option>';
}$ymenu .= '</select>';

mysql_close($db);
//	setcookie('curid', $curid);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
	<title>Template</title>
	<meta content="text/html; charset=UTF-8" />
	<style type="text/css">
		body{
			background: #FFF;
		}
	</style>	
</head>
<body>
<form method="get" action="<?=$self?>">
	<?=$ymenu?>
	<?=$option?>
	<input type="submit" />
</form>
	<img src="RAWhtml-parser-imageGEN.php" alt="RAWhtml-parser-imageGEN" />
</body>
</html>